﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using PMSA.Framework.Log;
using System.Text;

public partial class Admin_Uc_Order_EditOrder : System.Web.UI.UserControl
{
    int orderid = 0;
    protected void Page_Load(object sender, EventArgs e)
    {

            if (Request.QueryString["oi"] != null)
            {
                try
                {
                    orderid = int.Parse(Request.QueryString["oi"].ToString());
                    Order obj = new Order().Select(orderid);
                    txtAdress.Text = obj.OrderCustomerAddress;
                    txtEmail.Text = obj.OrderCustomerEmail;
                    txtName.Text = obj.OrderCustomerName;
                    txtNote.Text = obj.OrderCustomerNote;
                    txtPhone.Text = obj.OrderCustomerPhone;

                    StringBuilder strDetail = new StringBuilder();
                    IList<OrderDetail> list = new Order().SelectDetail(orderid);
                    obj.OrderDetails = list;
                    foreach (OrderDetail item in list)
                    {
                        strDetail.AppendFormat(_formatOrder, item.ProductId, item.ProductName, item.Quantity, item.PriceAtBuy, item.TotalPrice());
                    }
                    strDetail.AppendFormat(_formatOrder, "", "", "", "<span style='color:red'>TOTAL PRICE</span>", "<span style='color:red'>" + obj.TotalPrice() + "</span>");
                    tbodyOrderDetailList.InnerHtml = strDetail.ToString();
                }
                catch(Exception ex)
                {
                    CLogManager.Write("EditOrder.Edit.PageLoad", ex.ToString(), "ADMIN");
                }
            }
        
    }
    protected void btnFinish_Click(object sender, EventArgs e)
    {
        if(orderid != 0)
            new Order().Finish(orderid);
    }
    protected void btnCancel_Click(object sender, EventArgs e)
    {
        if (orderid != 0)
            new Order().Cancel(orderid);
    }
    string _formatOrder = "<tr>" +
"<td class='a-center'>{0}</td>" +
"<td><a href='#'>{1}</a></td>" +
"<td>{2}</td>" +
"<td>{3}</td>" +
"<td>{4}</td>" +
"</tr>";
}